﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhSystemBLL.orderData;
using dhSystemBLL.produceBLL;
using baseSet.importExport;
using dhsystem.Main;
using dhDataAcess.baseBLL;

namespace dhsystem.produceForm.Stock
{
    public partial class Frmpackbaobiao : Form
    {
        packStockInBLL packStockIn = new packStockInBLL();
        public Frmpackbaobiao()
        {
            InitializeComponent();
        }

        private void Frmpackbaobiao_Load(object sender, EventArgs e)
        {
           
            bgSourcepacking.DataSource = packStockIn.getVpackbaobiaoAllBybillStatus("包装中");
            dGridpacking.DataSource = bgSourcepacking;
            DcolumnSet.colSet(moduleInfo.Vpackbaobiao, dGridpacking);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridpacking.RowCount.ToString() + "条";
        }

        private void buttonQuery_Click(object sender, EventArgs e)
        {
            bgSourcepacking.DataSource = basicSql.getVpackbaobiaoIIII("%" + textMatNameQuery.Text + "%");
            dGridpacking.DataSource = bgSourcepacking;
            DcolumnSet.colSet(moduleInfo.orderDetail, dGridpacking);
        }

        private void buttupdate_Click(object sender, EventArgs e)
        {
           
            bgSourcepacking.DataSource = packStockIn.getVpackbaobiaoAllBybillStatus("包装中");
            dGridpacking.DataSource = bgSourcepacking;
            DcolumnSet.colSet(moduleInfo.Vpackbaobiao, dGridpacking);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridpacking.RowCount.ToString() + "条";
        }

        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.Vpackbaobiao);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridpacking.DataSource = query.rTable;
            }
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.Vpackbaobiao, dGridpacking, "包装信息");
            frm.ShowDialog();
        }

        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            //包装中
            if (e.TabPage == tabPage1)
            {
                bgSourcepacking.DataSource = packStockIn.getVpackbaobiaoAllBybillStatus("包装中");
                dGridpacking.DataSource = bgSourcepacking;
                DcolumnSet.colSet(moduleInfo.Vpackbaobiao, dGridpacking);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridpacking.RowCount.ToString() + "条";
            }
            //包装完成
            if (e.TabPage == tabPage2)
            {
                bSourcepackend.DataSource = packStockIn.getVpackbaobiaoAllBybillStatus("包装完成");
                dGridViewpackend.DataSource = bSourcepackend;
                DcolumnSet.colSet(moduleInfo.Vpackbaobiao, dGridViewpackend);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridViewpackend.RowCount.ToString() + "条";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bSourcepackend.DataSource = basicSql.getVpackbaobiaoI("%" + textBox1.Text + "%");
            dGridViewpackend.DataSource = bSourcepackend;
            DcolumnSet.colSet(moduleInfo.Vpackbaobiao, dGridViewpackend);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bSourcepackend.DataSource = packStockIn.getVpackbaobiaoAllBybillStatus("包装完成");
            dGridViewpackend.DataSource = bSourcepackend;
            DcolumnSet.colSet(moduleInfo.Vpackbaobiao, dGridViewpackend);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridViewpackend.RowCount.ToString() + "条";
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.Vpackbaobiao);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridViewpackend.DataSource = query.rTable;
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.Vpackbaobiao);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridViewpackend.DataSource = query.rTable;
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dGridpacking_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void 订单终结ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否终结订单！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {


                    basicSql.getpackStockInMasterbillStatusUpdate(dGridpacking.CurrentRow.Cells["orderDetailNo"].Value.ToString(), "包装完成");
                    basicSql.getorderDetailStatusUpdate(dGridpacking.CurrentRow.Cells["orderDetailNo"].Value.ToString());//更新订单明细状态
                    MessageBox.Show("已完结订单");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        
        }
    }
}
